using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WLYT.Application.Interfaces;
using WLYT.Domain.Model;
using WLYT.Repository;

namespace WLYT.Application.Services
{	
    public class AgvLogService : BaseService<AgvLog>, IAgvLogService
    {
        public ISqlSugarRepository<AgvLog> AgvLogRepository;
        public AgvLogService(ISqlSugarRepository<AgvLog> agvLogRepository) : base(agvLogRepository)
        {
            AgvLogRepository = agvLogRepository;
        }

        public async Task<Tuple<IList<AgvLog>, int>> GetModelsByPageAsync(DateTime? time, string search, int pageSize, int pageIndex)
        {
            Expressionable<AgvLog> exp = Expressionable.Create<AgvLog>();
            exp.AndIF(time != null, p => SqlFunc.Between(p.CreateTime, time, (time ?? DateTime.Now).AddDays(1)));
            exp.AndIF(!string.IsNullOrEmpty(search), p => p.StartPosition.Contains(search) || p.EndPosition.Contains(search));
            return await GetPageListAsync(exp, pageSize, pageIndex, p => p.Id);
        }
    }
}